package com.wechatapp.mengyao.poetry.service.impl;

import com.wechatapp.mengyao.poetry.core.JsonUtils;
import com.wechatapp.mengyao.poetry.entity.GlobalConfig;
import com.wechatapp.mengyao.poetry.mapper.GlobalConfigMapper;
import com.wechatapp.mengyao.poetry.service.GlobalConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yanghuaxu
 * @date 2025/9/7 17:20
 */
@Service
public class GlobalConfigServiceImpl implements GlobalConfigService {

    @Autowired
    private GlobalConfigMapper globalConfigMapper;

    @Override
    public <T> T getConfig(String configKey, Class<T> dataType) {
        GlobalConfig condition = new GlobalConfig();
        condition.setConfigKey(configKey);
        GlobalConfig config = globalConfigMapper.selectOne(condition);
        if (config != null) {
            return JsonUtils.parseObject(config.getConfigValue(), dataType);
        }
        return null;
    }

}
